<?php
namespace app\search\admin;
use app\common\controller\AdminBase;
use app\search\model\Lists AS Model;
use app\common\traits\AddEditList;
class Listst extends AdminBase{
	use AddEditList;
	protected $model;
	protected $form_items=[];
	protected $list_items;
	protected $tab_ext;
	protected function _initialize(){
		parent::_initialize();
		$this->model=new Model();
	}
	/**
	 * 内容首页
	 * @return mixed|string
	 */
	public function index(){
		$this->tab_ext=['page_title'=>'内容管理',];
		$this->list_items=[
			['aid','信息id','text'],
			['module','所属模型','text'],
			[
				'aid',
				'内容',
				'callback',
				function($id,$rs){
					$links=iurl($rs['module'].'/content/show',['id'=>$rs['aid']]);
					return "<a href='$links' target='_blank'>$rs[data]</a> ";
				}
			],
		];
		$this->tab_ext['top_button']=[
			['type'=>'delete'],
			['url'=>auto_url('qingchu'),'title'=>'清空内容表(清空后需要重新导入)','class'=>' alert']
		];
		$this->tab_ext['right_button']=[
			['type'=>'delete'],
		];
		$data=$this->model->order('id','desc')->paginate(20);
		return $this->getAdminTable($data);
	}
	/**
	 * 添加
	 * @return mixed|string
	 */
	public function add(){ }
	/**
	 * 修改
	 * @param null $id
	 * @return mixed|string
	 */
	public function edit(){ }
	/**
	 * 删除
	 * @param $ids
	 */
	public function delete($ids){
		if(empty($ids)){
			$this->error('ID有误');
		}
		$ids=is_array($ids)?$ids:[$ids];
		if($this->model->destroy($ids)){
			$this->success('删除成功','index');
		}else{
			$this->error('删除失败');
		}
	}
	/**
	 * 清空数据表
	 */
	public function qingchu(){
		into_sql("TRUNCATE TABLE qb_search_content;",true,0);
		$this->success('清空表成功','index');
	}
}
